﻿using MahApps.Metro.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace LunarSF.SHomeWorkshop.LunarMarkdownEditor
{
    /// <summary>
    /// LineLeaderTextSettingDialog.xaml 的交互逻辑
    /// </summary>
    public partial class LineLeaderTextSettingDialog : MetroWindow
    {
        public LineLeaderTextSettingDialog()
        {
            InitializeComponent();

            var manager = App.ConfigManager;

            if (manager != null)
            {
                tbxA.Text = manager.Get("LeaderTextRegsA");

                tbxB.Text = manager.Get("LeaderTextRegsB");

                var text = manager.Get("ReplaceLeaderChar");
                if (string.IsNullOrWhiteSpace(text))
                {
                    tbxReplaceTextFstChar.Text = "$";
                }
                else
                {
                    tbxReplaceTextFstChar.Text = text.Substring(0, 1);
                }
            }
            else
            {
                LMessageBox.Show("发生异常，无法载入配置文件，继续操作的结果将不会被保存！", Globals.AppName, MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }
        }

        private void btnOK_Click(object sender, RoutedEventArgs e)
        {

            var manager = App.ConfigManager;

            if (manager != null)
            {
                Globals.MainWindow.LeaderTextRegsA = tbxA.Text;
                Globals.MainWindow.LeaderTextRegsB = tbxB.Text;
                Globals.MainWindow.ReplaceLeaderChar = tbxReplaceTextFstChar.Text;
                manager.Set("LeaderTextRegsA", tbxA.Text);
                manager.Set("LeaderTextRegsB", tbxB.Text);
                manager.Set("ReplaceLeaderChar", Globals.MainWindow.ReplaceLeaderChar);
            }

            this.Close();
        }

        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
    }
}
